<template>
  <el-dialog v-model="dialogVisible" draggable title="修改密码" width="500px">
    <el-form>
      <el-form-item label="请输入新密码：">
        <el-input v-model="pwd1" type="password"></el-input>
      </el-form-item>
      <el-form-item label="请确认新密码：">
        <el-input v-model="pwd2" type="password"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="SaveChangePwd">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { ElMessage } from "element-plus";
import { requestSysUserUpdatePwd } from "@/api/modules/sysUser";
import { ResultData } from "@/api/interface";
import { RespOk } from "@/constant/codes";

const dialogVisible = ref(false);
let pwd1 = ref("");
let pwd2 = ref("");
const openDialog = () => {
  dialogVisible.value = true;
};
const SaveChangePwd = () => {
  if (pwd1.value == "") {
    ElMessage({ type: "error", message: "请输入新密码" });
    return;
  }
  if (pwd1.value != pwd2.value) {
    ElMessage({ type: "error", message: "两次输入的密码不一致" });
    return;
  }
  requestSysUserUpdatePwd({ password: pwd1.value }).then((res: ResultData) => {
    if (res.code == RespOk) {
      ElMessage({ type: "success", message: "密码修改完成" });
      dialogVisible.value = false;
    }
  });
};
defineExpose({ openDialog });
</script>
